<html>
<head><meta charset="utf-8"><title>Signalling the presence of -Z build-std · t-cargo · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/index.html">t-cargo</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Signalling.20the.20presence.20of.20-Z.20build-std.html">Signalling the presence of -Z build-std</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="227718174"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Signalling%20the%20presence%20of%20-Z%20build-std/near/227718174" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> jdm <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Signalling.20the.20presence.20of.20-Z.20build-std.html#227718174">(Feb 25 2021 at 04:59)</a>:</h4>
<p>I filed an issue against the autocfg crate today (<a href="https://github.com/cuviper/autocfg/issues/34">https://github.com/cuviper/autocfg/issues/34</a>) where it breaks in the presence of -Z build-std, because it doesn't know to add the sysroot when running its rustc probes. Is there some way for crates to discover this reliably?</p>



<a name="227722291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Signalling%20the%20presence%20of%20-Z%20build-std/near/227722291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Signalling.20the.20presence.20of.20-Z.20build-std.html#227722291">(Feb 25 2021 at 06:02)</a>:</h4>
<p>I don't even really care about <code>-Z build-std</code> per se -- just need to know what flags to give <code>rustc</code> for the target</p>



<a name="227722350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Signalling%20the%20presence%20of%20-Z%20build-std/near/227722350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Signalling.20the.20presence.20of.20-Z.20build-std.html#227722350">(Feb 25 2021 at 06:03)</a>:</h4>
<p>see also <a href="https://github.com/cuviper/autocfg/issues/15">https://github.com/cuviper/autocfg/issues/15</a></p>



<a name="227767541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Signalling%20the%20presence%20of%20-Z%20build-std/near/227767541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Signalling.20the.20presence.20of.20-Z.20build-std.html#227767541">(Feb 25 2021 at 13:37)</a>:</h4>
<p>Crates can come either from sysroot or --extern at any time, inside or outside of cargo. I would be surprised if there was a way to detect which way a crate would be loaded without replicating the crate search mechanism in rustc or having access to the flags that are passed to rustc. For rustflags you could look at cargo's build plan, but the issue is that you'd have no idea how the cargo was invoked in the first place (and so you cannot invoke cargo the right way to generate said build plan)</p>



<a name="227767838"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Signalling%20the%20presence%20of%20-Z%20build-std/near/227767838" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Signalling.20the.20presence.20of.20-Z.20build-std.html#227767838">(Feb 25 2021 at 13:40)</a>:</h4>
<p>It is entirely plausible that people specify a <code>RUSTFLAGS='--sysroot=/my_custom_path/'</code> or <code>RUSTFLAGS='--extern specific_lib=/my_custom_path/lib.rlib'</code> and expect <code>extern specific_lib</code> to work correctly in either instance.</p>



<a name="227767956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Signalling%20the%20presence%20of%20-Z%20build-std/near/227767956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Signalling.20the.20presence.20of.20-Z.20build-std.html#227767956">(Feb 25 2021 at 13:40)</a>:</h4>
<p>Now as far as this specific issue is concerned I would call it not-a-bug? Its definitely specified in the function name that it only probes the sysroot, and std is not required to come from a sysroot.</p>



<a name="227814225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Signalling%20the%20presence%20of%20-Z%20build-std/near/227814225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Signalling.20the.20presence.20of.20-Z.20build-std.html#227814225">(Feb 25 2021 at 18:32)</a>:</h4>
<p>huh, I would have guessed that <code>-Z build-std</code> would just prepare a path for <code>--sysroot</code>, but instead it presents those as <code>--extern 'noprelude:core=... --extern 'noprelude:std=...</code> etc.</p>



<a name="227814435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Signalling%20the%20presence%20of%20-Z%20build-std/near/227814435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Signalling.20the.20presence.20of.20-Z.20build-std.html#227814435">(Feb 25 2021 at 18:33)</a>:</h4>
<p>so <code>probe_sysroot_crate("std") -&gt; false</code> is correct, but pedantically so</p>



<a name="227815022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Signalling%20the%20presence%20of%20-Z%20build-std/near/227815022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Signalling.20the.20presence.20of.20-Z.20build-std.html#227815022">(Feb 25 2021 at 18:37)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span> <code>autocfg</code> does try to deal with <code>RUSTFLAGS</code> to some extent, but that's also messy between what is applied to host vs. target, and it doesn't try to find all the config files that may also set flags</p>



<a name="227815140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Signalling%20the%20presence%20of%20-Z%20build-std/near/227815140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Signalling.20the.20presence.20of.20-Z.20build-std.html#227815140">(Feb 25 2021 at 18:38)</a>:</h4>
<p>I think it would be nice if cargo just set something like <code>TARGET_RUSTFLAGS</code> for the build script invocation, just as it sets <code>RUSTC</code>, <code>TARGET</code>, etc</p>



<a name="227815157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Signalling%20the%20presence%20of%20-Z%20build-std/near/227815157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Signalling.20the.20presence.20of.20-Z.20build-std.html#227815157">(Feb 25 2021 at 18:38)</a>:</h4>
<p>Conversely it is plausible that some build systems would put a bunch dependency libraries into a sysroot (specified through a flag) in order to avoid dealing with <code>--extern</code>.</p>



<a name="227817686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Signalling%20the%20presence%20of%20-Z%20build-std/near/227817686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Signalling.20the.20presence.20of.20-Z.20build-std.html#227817686">(Feb 25 2021 at 18:55)</a>:</h4>
<p>To the best of my knowledge the sysroot layout is an implementation detail and as such unstable.</p>



<a name="227820159"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Signalling%20the%20presence%20of%20-Z%20build-std/near/227820159" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Signalling.20the.20presence.20of.20-Z.20build-std.html#227820159">(Feb 25 2021 at 19:10)</a>:</h4>
<p>for the most part, <code>autocfg</code> just wants to invoke rustc the same way that the target will be built</p>



<a name="227820518"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Signalling%20the%20presence%20of%20-Z%20build-std/near/227820518" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Signalling.20the.20presence.20of.20-Z.20build-std.html#227820518">(Feb 25 2021 at 19:12)</a>:</h4>
<p>I don't really care about which flags are used, if there's a way to at least discover those flags</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>